const decoder = new TextDecoder();
const encoder = new TextEncoder();

export function binaryDataToString(data: Uint8Array): string {
  return decoder.decode(data);
}

export function binaryDataToJson<T>(data: Uint8Array): T {
  return JSON.parse(binaryDataToString(data));
}

export function stringToBinaryData(str: string): Uint8Array {
  return encoder.encode(str);
}